package com.example.t470p.facechecktickets;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.t470p.facechecktickets.response.GateListResponse;

import java.util.List;

public class PopListAdapter extends BaseAdapter {
    SharedPreferences sp;
    SharedPreferences.Editor edit;
    Context context;
    List<GateListResponse.GateInfoListBean> list;



    public PopListAdapter(Context context,  List<GateListResponse.GateInfoListBean> list) {
        this.context = context;
        this.list = list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.pop_listview_layout,null);
            holder = new ViewHolder();

            holder.img_list = (ImageView) convertView.findViewById(R.id.pop_list_img_link);
            holder.tv_list_name = (TextView) convertView.findViewById(R.id.pop_list_tv_name);
            holder.tv_list_no = (TextView) convertView.findViewById(R.id.pop_list_tv_no);
            convertView.setTag(holder);//绑定ViewHolder对象
        }else {
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象
        }
        sp = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        int tag=sp.getInt("position",0);
        if (tag==position) {
            holder.img_list.setVisibility(View.VISIBLE);
            holder.tv_list_name.setText(list.get(position).getGateName());
            holder.tv_list_no.setText(list.get(position).getGateNo());
        }else {
            holder.img_list.setVisibility(View.INVISIBLE);
            holder.tv_list_name.setText(list.get(position).getGateName());
            holder.tv_list_no.setText(list.get(position).getGateNo());
        }
        return convertView;
    }

    /*存放控件*/
    public final class ViewHolder{
        public   ImageView img_list;
        public TextView tv_list_name;
        public TextView tv_list_no;
    }


}
